import libtcodpy as L#imports for beginning
from Commons import *
global mymap
try:
	import psyco#improves preformance of python
except ImportError:
	print "Warning, psyco not installed, program will run slower"
L.console_init_root(SCREEN_WIDTH,SCREEN_HEIGHT,"Dungeon Builder")#start the game
#other imports
import os, sys
import UI
from Map import *
from AreaSelector import *
from UISwitcher import *
#XXX: check memory footprint of blitted screens
	

a = 0
L.sys_set_fps(getConfig("MAX FPS"))#set fps
sys.setrecursionlimit(10000000)#to prevent recursion freezes

titleui = UI.TitleScreen()
mapui = UI.MapUI()
ui = titleui

Game().attach(A_UI_READER,ui)
Game().attach(A_MAP_VIEW,None)
Game().attach(A_UI_SWITCH,SwitchUI)
while (not L.console_is_window_closed()):
	key = L.console_check_for_keypress(L.KEY_PRESSED)
	setKey(key)#set the key to the pressed key
	keyr = L.console_check_for_keypress(L.KEY_RELEASED)
	m = L.mouse_get_status()
	L.console_clear(0)
	Game()[A_UI_READER].basicUI(key,keyr,m)#the ui/drawing if rendermap is not defined
	if (Game()[A_UI_READER].rendermap):
		Game()[A_MAP_VIEW].blitView()
		Game()[A_UI_READER].displayOverView()
	L.console_flush()
if (Game()[A_UI_READER].cansave):#try to save the file if able
	if (len(Game().loadedfile) == 0):
		Game().save(SAVEFILE_PATH+SaveFileScreen()+".sav")
	else:
		Game().save(Game().loadedfile)
